package com.pan.studentmaster;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CheckBox;
import android.widget.SeekBar;

public class Pref extends Activity {
	
	static final public String		FAST_PAGE = "FAST_PAGE";
	static final public String		FLING_SENSITIVITY = "FLING_SENSITIVITY";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_pref);
		_fastPageTurn = (CheckBox)findViewById(R.id.fastPageTurn);
		SharedPreferences prefs = Main.instance().getSharedPreferences(Main.APP_NAME, Context.MODE_PRIVATE);
		_fastPageTurn.setChecked(prefs.getBoolean(FAST_PAGE, true));
		_flingSensitivity = (SeekBar)findViewById(R.id.flingSensitivity);
		_flingSensitivity.setProgress(prefs.getInt(FLING_SENSITIVITY, 2000));
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.pref, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	
	@Override
	public void onStop() {
		super.onStop();
		SharedPreferences prefs = Main.instance().getSharedPreferences(Main.APP_NAME, Context.MODE_PRIVATE);
		Editor editor = prefs.edit();
		editor.putBoolean(FAST_PAGE, _fastPageTurn.isChecked());
		editor.putInt(FLING_SENSITIVITY, _flingSensitivity.getProgress());
		editor.commit();
	}
	
	private CheckBox	_fastPageTurn;
	private SeekBar		_flingSensitivity;
}
